/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author milokokok
 */
@Entity
@Table(name = "baskets")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Baskets.findAll", query = "SELECT b FROM Baskets b"),
    @NamedQuery(name = "Baskets.findById", query = "SELECT b FROM Baskets b WHERE b.id = :id"),
    @NamedQuery(name = "Baskets.findByPrice", query = "SELECT b FROM Baskets b WHERE b.price = :price")})
public class Baskets implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id")
    private Long id;
    @Basic(optional = false)
    @NotNull
    @Column(name = "price")
    private double price;
    @JoinColumn(name = "id_order", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Orders idOrder;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idBasket")
    private Collection<ItemBasket> itemBasketCollection;

    public Baskets() {
    }

    public Baskets(Long id) {
        this.id = id;
    }

    public Baskets(Long id, double price) {
        this.id = id;
        this.price = price;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public Orders getIdOrder() {
        return idOrder;
    }

    public void setIdOrder(Orders idOrder) {
        this.idOrder = idOrder;
    }

    @XmlTransient
    public Collection<ItemBasket> getItemBasketCollection() {
        return itemBasketCollection;
    }

    public void setItemBasketCollection(Collection<ItemBasket> itemBasketCollection) {
        this.itemBasketCollection = itemBasketCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Baskets)) {
            return false;
        }
        Baskets other = (Baskets) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "models.Baskets[ id=" + id + " ]";
    }
    
}
